package com.chixing.day11.day11_Hom;

public class LinkString {

    class ListNode{
        ListNode next;
        public ListNode(int i) {
        }
    }
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode result = new ListNode(0);
        result.next = head;
        ListNode pre = null;
        ListNode cur = result;
        int i = 1;
        while (head != null) {
            if (i >= n) {
                pre = cur;
                cur = cur.next;
            }
            head = head.next;
            i ++;
        }
        pre.next = pre.next.next;
        return result.next;
    }
}
